namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0125 : DbMigration
    {
        public override void Up()
        {
            try
            {

                this.Sql(@"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hrm_mp_position_work_on_duty]') AND type in (N'U'))
                            BEGIN
                            Drop TABLE [dbo].[hrm_mp_position_work_on_duty]
                            END");
            } catch{}
            CreateTable(
                "dbo.hrm_mp_position_work_on_duty",
                c => new
                    {
                        wod_seq = c.Int(nullable: false, identity: true),
                        ref_no = c.String(),
                        to_emp_seq = c.Int(),
                        by_emp_seq = c.Int(),
                        start_date = c.Int(nullable: false),
                        end_date = c.Int(nullable: false),
                        see_old_message = c.Boolean(nullable: false),
                        description = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(nullable: false),
                        created_when = c.DateTime(nullable: false),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.wod_seq)
                .ForeignKey("dbo.hrm_ps_employees", t => t.to_emp_seq)
                .ForeignKey("dbo.hrm_ps_employees", t => t.by_emp_seq)
                .Index(t => t.to_emp_seq)
                .Index(t => t.by_emp_seq);
            
            AddColumn("dbo.SysTask", "RelatedTo", c => c.Int());
            AddForeignKey("dbo.SysTask", "RelatedTo", "dbo.hrm_ps_employees", "emp_seq");
            CreateIndex("dbo.SysTask", "RelatedTo");
        }
        
        public override void Down()
        {
            DropIndex("dbo.hrm_mp_position_work_on_duty", new[] { "by_emp_seq" });
            DropIndex("dbo.hrm_mp_position_work_on_duty", new[] { "to_emp_seq" });
            DropIndex("dbo.SysTask", new[] { "RelatedTo" });
            DropForeignKey("dbo.hrm_mp_position_work_on_duty", "by_emp_seq", "dbo.hrm_ps_employees");
            DropForeignKey("dbo.hrm_mp_position_work_on_duty", "to_emp_seq", "dbo.hrm_ps_employees");
            DropForeignKey("dbo.SysTask", "RelatedTo", "dbo.hrm_ps_employees");
            DropColumn("dbo.SysTask", "RelatedTo");
            DropTable("dbo.hrm_mp_position_work_on_duty");
        }
    }
}
